# 作者: 陈其志 
# 2025年02月18日13时34分51秒 
# 2716847110@qq.com


# python中是加载到内存中，是预加载
def inner_vary_1():
    """
    局部变量
    :return:
    """
    num = 100  # int是局部变量
    print(f"num = {num},num_id = {id(num)}")
    num = 200
    print(f"num = {num},num_id = {id(num)}")


def inner_vary_2():
    """
    局部变量
    :return:
    """
    num = 100  # int是局部变量
    print(f"num = {num},num_id = {id(num)}")
    num = 200
    print(f"num = {num},num_id = {id(num)}")


def global_vary():
    """
    全局变量：在函数中需要修改全局变量，需要使用 global 进行声明
    :return:
    """
    global g_num
    print(g_num)
    print(id(g_num))
    g_num = 100
    print(id(g_num))


if __name__ == '__main__':
    # inner_vary_1()
    # inner_vary_2()
    g_num = 300
    print(f"修改前全局变量g_num的id：{id(g_num)}")
    global_vary()
    print(g_num)
    print(f"修改后全局变量g_num的id：{id(g_num)}")
